package com.yurun.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;

/**
 * @author 宫静雨
 */
public class CodeGenerator {

    public static void main(String[] args) {
        DataSourceConfig.Builder dataSourceConfigBuilder = new DataSourceConfig.Builder(
                "jdbc:mysql://localhost:3306/testing",
                "root",
                "Oracle12")
                .dbQuery(new MySqlQuery())
                .typeConvert(new MySqlTypeConvert())
                .keyWordsHandler(new MySqlKeyWordsHandler());

        FastAutoGenerator.create(dataSourceConfigBuilder)
                .globalConfig(builder -> builder.outputDir("./src/main/java")
                        .author("宫静雨")
                        .enableSwagger()
                        .disableOpenDir()
                        .dateType(DateType.TIME_PACK)
                        .commentDate("yyyy-MM-dd HH:mm:ss"))
                .packageConfig(builder -> builder.parent("com.yurun")
                        .entity("entity")
                        .controller("controller")
                        .service("service")
                        .serviceImpl("service.impl")
                        .mapper("mapper")
                        .xml("mapper")
                )
                .strategyConfig(builder -> builder.addInclude("classes", "student",
                        "course", "score"))
                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }
}